package com.lagou.k8s.controller;

import com.lagou.k8s.model.StudentEntity;
import com.lagou.k8s.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "学生管理")
@RestController
@RequestMapping("/student")
public class StudentController {

    private StudentService studentService;

    @ApiOperation("添加学生")
    @PutMapping("")
    public String add(@ApiParam("姓名") @RequestParam("name") String name, @RequestParam("age") @ApiParam("年龄") Integer age){
        studentService.save(name, age);

        return "添加成功";
    }

    @ApiOperation("修改学生")
    @PostMapping("")
    public String update(@ApiParam("编号") @RequestParam("id") Integer id,@ApiParam("姓名") @RequestParam("name") String name, @ApiParam("年龄") @RequestParam("age")Integer age){
        studentService.update(id, name, age);

        return "修改成功";
    }

    @ApiOperation("查询学生")
    @GetMapping("")
    public StudentEntity get(@ApiParam("编号") @RequestParam("id")Integer id){
        return studentService.getStudent(id);
    }

    @ApiOperation("删除学生")
    @DeleteMapping("")
    public String  delete(@ApiParam("编号") @RequestParam("id")Integer id){
        studentService.delete(id);

        return "删除成功";
    }


    @Autowired
    public void setStudentService(StudentService studentService) {
        this.studentService = studentService;
    }
}
